/-app ...
/-app/tests ...
TestCase.ts
TestPage.ts
Application.ts
/-boot
/-imports
/-storage
/-tests
/-typings
stringUtils.ts
teapo.html
1
module teapo.app.tests {
2
 
3
  export class TestCase {
4
 
5
    state = ko.observable(TestCase.State.NotStarted);
6
    runtime = ko.observable<number>(null);
7
    failure = ko.observable<Error>(null);
8
 
9
    private _started = -1;
10
 
11
    constructor(
12
      public name: string,
13
      private _test: Function) {
14
    }
15
 
16
    start() {
17
      if (this.state() !== TestCase.State.NotStarted)
18
        throw new Error('Test case already started (' + TestCase.State[this.state()] + ').');
19
 
20
      this.state(TestCase.State.Running);
21
      this.runtime(0);
22
      this._started = 0;
23
 
24
      var failed = false;
25
      var failure: Error = null;
26
      
27
      try {
28
        var test = this._test;
29
        test();
30
      }
31
      catch (error) {
32
        failed = true;
33
        failure = error;
34
      }
35
 
36
      var now = Date.now();
37
      this.runtime(now - this._started);
38
 
39
      if (failed) {
40
        this.failure(failure);
41
        this.state(TestCase.State.Failed);
42
      }
43
      else { 
44
        this.state(TestCase.State.Succeeded);
45
      }
46
 
47
    }
48
  }
49
 
50
  export module TestCase {
51
 
52
    export enum State {
53
      NotStarted,
54
      Running,
55
      Succeeded,
56
      Failed
57
    }
58
 
59
  }
60
 
61
}